#ifndef _GRO_GROUP_H__
#define _GRO_GROUP_H__

#include "GRO_Gui.h"
#include <list>
#include <vector>


namespace GRO
{

class Grid
{
public:
    std::vector< std::vector<Widget*> > contents; // 2-d array: row, then col
    unsigned int rows;
    unsigned int columns;
    Dimensions currentAddPos;
    
    bool useSizeLimit;

    Grid();

    Widget* get(unsigned int row, unsigned int col);
    void set(unsigned int row, unsigned int col, Widget* value);
    void add(Widget* value, bool newRow = false);
    void setSize(unsigned int Rows, unsigned int Columns);

};







class Group : public Widget
{
public:
    Grid grid;
    //NavGraph* graph;
    std::list<Widget*> pins;

    //ScrollBar* scrollX;
    //ScrollBar* scrollY;

    enum AlignEnum
    {
        //ALIGN_NONE,
        ALIGN_LEFT_UP,
        //ALIGN_LEFT_DOWN,
        //ALIGN_RIGHT_UP,
        //ALIGN_RIGHT_DOWN,
        ALIGN_UP_LEFT
        //ALIGN_UP_RIGHT,
        //ALIGN_DOWN_LEFT,
        //ALIGN_DOWN_RIGHT,
        //ALIGN_CENTER
    };

    AlignEnum alignment;
    int xPadding, yPadding;
    bool autoFitContents;
    Uint16 extentX;  // How much area the widgets take up
    Uint16 extentY;

    //int oldXScroll, oldYScroll;

    Rect displacement;  // Group side padding

    Group();
    Group(const Dimensions& dims);
    
    virtual ~Group();

    void sortPinned();

    //void updateRelCoords();

    // change dimensions of the group to fit the widgets
    //void fitContents(bool usePinned = true);

    //void wrapContents(bool continueOnWrappedLines = true, bool compressSpaces = false);

    void setGridSize(unsigned int rows, unsigned int columns);

    virtual void set(unsigned int row, unsigned int col, Widget* widget);

    virtual void add(Widget* widget, bool newRow = false);
    virtual void addToNewRow(Widget* widget);

    /*void setAddOrder(AddOrderEnum order);
    AddOrderEnum getAddOrder();*/

    // pin to current x,y
    virtual void pin(Widget* widget, int x, int y);

    // FindValue needs testing...  The &pins == NULL return value is weird.
    virtual void unpin(Widget* widget);

    virtual void resize(Uint16 w, Uint16 h, bool parentResize = false);

    virtual Widget* findWidget(int mx, int my);  // Return the widget clicked on
    
    virtual std::list<Widget*> getChildren();

    virtual Widget* action(PointerCursor* mouse, ActionEnum actionType);
    virtual Widget* action(NavCursor* nav, ActionEnum actionType);

    //virtual Widget* scroll(DirectionEnum direction, float numIncrements);

    //virtual void setScroll(ScrollBar* scrollbar, DirectionEnum direction);

    virtual void draw(SDL_Rect* clipRect);
    virtual void update();
    virtual void move(int x, int y, bool relative = 1);
    virtual void updatePositions(bool usePinnedExtents = true);

    //virtual void align(Widget* widget);
    //virtual void applyTheme(Theme* theme, bool recursive = 0);
    virtual void setGui(Gui* Gui);
    virtual void setPanel(Panel* Panel);
    virtual void setGroup(Group* Group);
    virtual Widget* mouseWheelEvent(Sint16 mx, Sint16 my);
    
    virtual TiXmlElement* save(TiXmlElement* parent);
    virtual bool load(TiXmlElement* w);

};


}

#endif
